package com.pxxy.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/******************
 * @Author yejf
 * @Description TODO
 */
@Controller   //相当于 @Component
public class HelloController {

    @RequestMapping("/hello")
    public void hello(HttpServletResponse response) throws IOException {
        //
        System.out.println("请求调用了 HelloController的hello()方法...");
        //
        response.setContentType("text/html;charset=utf-8");
        final PrintWriter out = response.getWriter();
        out.println("<h2>欢迎访问hello方法</h2>");
        //
        out.close();
    }

    @RequestMapping(value = "/welcome",produces = "text/html;charset=utf-8")
    @ResponseBody    //表示以此方法的返回值来直接响应客户端。
    public String welcome() {
        return "<h2>欢迎来到我的页面</h2>";
    }

    //@RequestMapping("/toLogin")
    public String toLogin() {
        //
        System.out.println("进入了HelloController的 toLogin方法，对的");
        //

        return "login";  //最终会被翻译成 : /WEB-INF/jsp/login.jsp
    }

}
